import { ADD_ITEM, DELETED_ITEM,CHANGE_INPUTVALUE} from './actionType';

const defaultState = {
    inputValue:'',
    listData:[]
}

const  todoListReducer = (state = defaultState, action) => {
      if(action.type == ADD_ITEM){
          const newState = JSON.parse(JSON.stringify(state));
          newState.listData.push(newState.inputValue);
          newState.inputValue = '';
          return newState;
      }
      if(action.type == DELETED_ITEM){
        const newState = JSON.parse(JSON.stringify(state));
        newState.listData.splice(action.value,1);
        return newState;
     }
     if(action.type == CHANGE_INPUTVALUE){
        const newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        return newState;
     }
        return state;
}
export default todoListReducer;